# Maintainer: Wu Zhenyu <wuzy01@qq.com>

_realname=scrcpy
pkgbase="mingw-w64-${_realname}"
pkgname="$MINGW_PACKAGE_PREFIX-${_realname}"
pkgver=2.1.1
pkgrel=1
pkgdesc='Display and control your Android device (mingw-w64)'
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/Genymobile/scrcpy'
license=('spdx:Apache-2.0')
depends=(
  "$MINGW_PACKAGE_PREFIX-android-tools"
  "$MINGW_PACKAGE_PREFIX-ffmpeg"
  "$MINGW_PACKAGE_PREFIX-SDL2"
  "$MINGW_PACKAGE_PREFIX-libusb"
)
makedepends=(
  "$MINGW_PACKAGE_PREFIX-cc"
  "$MINGW_PACKAGE_PREFIX-meson"
  "$MINGW_PACKAGE_PREFIX-pkgconf"
)
source=("${_realname}-${pkgver}.tar.gz::$url/archive/v${pkgver}.tar.gz"
        "$url/releases/download/v${pkgver}/${_realname}-server-v${pkgver}")
sha256sums=('6f3d055159cb125eabe940a901bef8a69e14e2c25f0e47554f846e7f26a36c4d'
            '9558db6c56743a1dc03b38f59801fb40e91cc891f8fc0c89e5b0b067761f148e')

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype release \
    -Dprebuilt_server="../${_realname}-server-v${pkgver}" \
    ../"${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/meson.exe install --destdir="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}"/LICENSE -t \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
